package com.dailyblue.java.mybatis.mybatis06.mapper;

import com.dailyblue.java.mybatis.mybatis06.bean.Dept;
import com.dailyblue.java.mybatis.mybatis06.bean.Emp;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

public interface DeptMapper {
    @Select("select * from dept where DEPTNO=#{id}")
    Dept findDeptByNo(int id);


    @Select("select * from dept where DEPTNO=#{id}")
    @Results({
            @Result(property = "deptNo", column = "deptno", id = true),
            @Result(property = "dname", column = "dname"),
            @Result(property = "emps", column = "deptno", javaType = Set.class,
                    many = @Many(select = "com.dailyblue.java.mybatis.mybatis06.mapper.EmpMapper.findEmpByDeptNo"))
    })
    Dept findDeptByNo2(int id);
}
